﻿using System;
using HK.Core.Common.Data;
using HK.Editor.GUIEx.Protocol.TreeView.Control;
using HK.Editor.GUIEx.Protocol.TreeView.Data;
using UnityEditor.IMGUI.Controls;
using UnityEngine;

namespace HK.Editor.GUIEx.TreeView.Control
{
    
    /// <summary>
    /// 异常 : 未知排序选项
    /// </summary>
    public class TableTreeUnknownSortOptionsException : Exception
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="iMessage">Message</param>
        public TableTreeUnknownSortOptionsException(string iMessage) : base(iMessage) {}
    }
    
    /// <summary>
    /// 异常 : 未知列异常
    /// </summary>
    public class TableTreeUnknownColumnException : Exception
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="iMessage">Message</param>
        public TableTreeUnknownColumnException(string iMessage) : base(iMessage) {}
    }
    
    /// <summary>
    /// 表树 - 多列
    /// </summary>
    /// <typeparam name="TBranch">树形数据类型</typeparam>
    public class MultiColTableTree<TBranch> : TableTree<TBranch>, IMultiColTableTree<TBranch>
        where TBranch : JsonData, ITreeBranch
    {
        /// <summary>
        /// 列数
        /// </summary>
        public int ColumnCount { get; protected set; } = 0;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="iState">State</param>
        /// <param name="iMode">Mode</param>
        /// <param name="iColumnCount">列数</param>
        /// <param name="iSortColumns">列排序回调</param>
        /// <param name="iDrawColumns">绘制列回调</param>
        /// <param name="iFoldoutColIndex">折叠箭头所在列索引</param>
        public MultiColTableTree(TreeViewState iState, ITableTreeDataContainer<TBranch> iMode,
            int iColumnCount, SortTableTree iSortColumns, DrawTableTreeColumn<TBranch> iDrawColumns,
            int iFoldoutColIndex) : base(iState, iMode, iSortColumns, iDrawColumns, iFoldoutColIndex)
        {
            ColumnCount = iColumnCount;
            // 重载
            Reload();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="iState">State</param>
        /// <param name="iHeader">Header</param>
        /// <param name="iDataContainer">数据同期</param>
        /// <param name="iColumnCount">列数</param>
        /// <param name="iSortColumns">列排序回调</param>
        /// <param name="iDrawColumns">绘制列回调</param>
        /// <param name="iFoldoutColIndex">折叠箭头所在列索引</param>
        public MultiColTableTree(TreeViewState iState, MultiColumnHeader iHeader,
            ITableTreeDataContainer<TBranch> iDataContainer, int iColumnCount, SortTableTree iSortColumns, 
            DrawTableTreeColumn<TBranch> iDrawColumns, int iFoldoutColIndex) :
            base(iState, iHeader, iDataContainer, iSortColumns, iDrawColumns, iFoldoutColIndex)
        {
            ColumnCount = iColumnCount;
            // 重载
            Reload();
        }
        
#region Draw
        
        /// <summary>
        /// 绘制自身
        /// </summary>
        /// <param name="iRect">制矩形范围</param>
        /// <param name="iEvent">Event</param>
        /// <returns>制矩形范围</returns>
        public Rect DrawSelf(Rect iRect, Event iEvent)
        {
            var displayRect = iRect;
            
            // 绘制
            OnGUI(iRect);
            return displayRect;
        }

#endregion
    }
    

}
